DAMN = (typeof DAMN != "undefined")?  DAMN : {};

DAMN.Preview = new function()
{
  this.AttachTo = function(parent) {
    var self = this;
    parent.tabs('add', '#tabs-Preview', "Preview");
    this.tab = $("#tabs-Preview");

    DAMN.AssetMananger.Register("asset", this.Preview.bind(this));

    $("#dialog-preview").dialog({
          autoOpen: false,
            modal: true,
            resizable: false,
            height:550,
            width:535,
          close: function() {
            $("#canvas").css({"width":'256px', "height":'256px'});
            $("#tabs-Preview").append($("#canvas"));
            $("#canvas").trigger('sizing');
          },
          open: function() {
            $("#canvas").css({"width":'512px', "height":'512px'});
            $("#dialog-preview").append($("#canvas"));
            $("#canvas").trigger('sizing');
          }
        });

    };

  this.Preview = function(op, el) {
    var self = this;
    self.tab.empty();
    if (op == 'SELECT') {
      if (DAMN.AssetMananger.selected.length == 1) {
        self.tab.empty();
        var div = $('<div>')
          .data('assetid', el.data('assetid'))
          .data('src_format', el.data('src_format'))
          .data('type', el.data('type'))
          .attr('id', 'canvas')
          .width(256)
          .height(256);
        self.tab.append(div);
        div.dblclick(function(){
          $('#dialog-preview').dialog('open');
        });
        div.DAMNPreview({
          'lazy': true,
          'sizex': 512,
          'sizey': 512
        });
      }
      else {
        self.tab.append("<p>Multiple selected."+DAMN.AssetMananger.selected.length+"</p>");
      }
    }
    else
    {
      self.tab.append("<p>Nothing selected.</p>");
    }
  };

};

